package com.example.commons;

import java.util.function.Function;

/**
 *  脱敏类型枚举
 */
public enum MaskTypeEnum {
    /*名称脱敏*/
    USERNAME(s->s.replaceAll("(\\S)\\S(\\S*)","$1*$2")),
    /*手机号脱敏*/
    PHONE(s->s.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2")),
    /*地址脱敏*/
    ADDRESS(s->s.replaceAll("(\\S{3})\\S{2}(\\S*)\\S{2}","$1****$2****"))
    ;

    // 成员变量
    private Function<String,String> function;  // Function函数接口特性:  入参T返回值R

    /**
     * 构造函数
     * @param function
     */
    MaskTypeEnum(Function<String, String> function) {
        this.function = function;
    }

    /**
     * 获取函数
     * @return
     */
    public Function<String, String> function(){
        return  this.function;
    }
}